package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.core.pojo.IouPorductApi;
import com.miplus.ccrm.core.service.conf.IouPorductApiService;
import com.miplus.ccrm.core.mapper.IouPorductApiMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* @author wangzl
* @description 针对表【iou_porduct_api】的数据库操作Service实现
* @createDate 2024-11-19 21:21:47
*/
@Service
public class IouPorductApiServiceImpl extends ServiceImpl<IouPorductApiMapper, IouPorductApi>
    implements IouPorductApiService{
    @Override
    @Transactional
    public void updateProductApi(List<String> apiList, String productId,String merchantId) {

        if (apiList != null) {
            for (String s : apiList) {
                IouPorductApi iouPorductApi = new IouPorductApi();
                iouPorductApi.setProductId(productId);
                iouPorductApi.setMerchantId(merchantId);
                iouPorductApi.setApiId(s);
                save(iouPorductApi);
            }
        }
    }

    @Override
    public List<String> getProductApiList(String productId,String merchantId) {

        if("HLDJQH01".equals(productId)){
            List<String> arr=new ArrayList<>();
            arr.add("207");//融资中台API 额度查询 207
            return arr;
        }


        //获取产品可用API接口
        return this.list(new MPJLambdaWrapper<>(IouPorductApi.class)
                .eq(IouPorductApi::getProductId, productId)
                .eq(IouPorductApi::getMerchantId, merchantId)
        ).stream().map(IouPorductApi::getApiId).collect(Collectors.toList());
    }
}




